package com.srit.map.business.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.srit.core.bean.Page;
import com.srit.core.ibatis.dao.SqlMapDao;
import com.srit.map.business.bean.Company;
import com.srit.map.business.bean.CompanyDescription;
import com.srit.map.business.bean.CompanySearch;
import com.srit.map.business.bean.SearchBean;
import com.srit.map.business.service.CompanyService;
@Service
public class CompanyServiceImpl implements CompanyService {
	@Autowired(required = true)
	private SqlMapDao sqlMapDao;

	@Override
	public CompanyDescription getCompanyDiscription(CompanySearch companySearch) {
		// TODO Auto-generated method stub
		CompanyDescription desc=(CompanyDescription)sqlMapDao.queryForObject("Company.getCompanyDesc", companySearch);
		return desc;
	}
	@Override
	public void InsertCompany(CompanyDescription com){
		sqlMapDao.save("Company.save", com);
	}
	@Override
	public void search(SearchBean searchBean,Page page) {
		Company company = new Company();
		if((searchBean.getSearchColumn()) .equals("name")){
			company.setName(searchBean.getSearchKey());
		}
		else if((searchBean.getSearchColumn()).equals("address") ){
			company.setName(searchBean.getSearchKey());
		}
		else if((searchBean.getSearchColumn()).equals("company_type") ){
			company.setCompany_type(searchBean.getSearchKey());
		}
		else if((searchBean.getSearchColumn()).equals("business_type") ){
			company.setBusiness_type(searchBean.getSearchKey());
		}
		page.setSp(company);
		System.out.print(page.getSp().getClass());
		
		sqlMapDao.queryForPage("Company.search", page);
	}
	//@Override
//	public CompanyDescription queryCompanyByName(String name) {
//		Company company = new Company();
//		company.setName(name);
//		CompanyDescription comDes = (CompanyDescription)sqlMapDao.queryForObject("Company.getCompanyDesc", company);
//		return comDes;
//	}
	@Override
	public void searchByKey(Page page) {
		sqlMapDao.queryForPage("Company.searchByKey", page);
		
	}
	@Override
	public void updateDes(CompanyDescription companyDescription) {
		sqlMapDao.update("Company.update", companyDescription);
		
	}
	
	
}
